<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="public/static" /}
    <style>
        .operating{
            display: none;
        }
        .layui-table tr{
            cursor: pointer;
        }
        .layui-table tr:hover > td .operating{
            display: block;
        }
    </style>
</head>
<body>

{include file="public/nav" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    {eq name="check.RoleroleAdd" value="1"}
                        <button class="layui-btn" onclick="common.openWindow('新增角色','{:url('Role/roleAdd')}','500','280')">
                            <i class="layui-icon">&#xe654;</i>新增角色
                        </button>
                    {/eq}
                    {eq name="check.RoleroleDelAll" value="1"}
                        <button class="layui-btn layui-btn-danger" onclick="dataDelAll()">
                            <i class="layui-icon">&#xe640;</i>批量删除
                        </button>
                    {/eq}
                </div>
                <div class="layui-card-body layui-table-body">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" lay-filter="checkbox" name="id" value="" lay-skin="primary">
                                </th>
                                <th>角色名</th>
                                <th>状态</th>
                                <th width="240">操作</th>
                            </tr>
                        </thead>
                        <tbody class="x-cate">
                            {volist name="info" id="vo"}
                                <tr cate-id="{$vo.ag_id}" fid="{$vo.ag_pid}" level="{$vo.level}">
                                    <td>
                                        <input type="checkbox" name="id[]" value="{$vo.ag_id}" lay-skin="primary">
                                    </td>
                                    <td><i class="layui-icon x-show" status='true'>|- </i>{$vo.ag_name}</td>
                                    <td>
                                        {eq name="vo.ag_status" value="1"}
                                            <span class="layui-badge layui-bg-green">启用</span>
                                        {else/}
                                            <span class="layui-badge">禁用</span>
                                        {/eq}
                                    </td>
                                    <td class="td-manage">
                                        <div class="operating">
                                            {eq name="check.RoleroleAdd" value="1"}
                                                <a href="javascript:;" onclick="common.openWindow('新增下级','{:url('Role/roleAdd',['pid'=>$vo.ag_id])}','500','280')">
                                                    <i class="layui-icon">&#xe654;</i>新增下级
                                                </a>
                                            {/eq}
                                            {eq name="check.RoleroleCompetence" value="1"}
                                                <a href="javascript:;" onclick="common.openWindow('编辑权限【{$vo.ag_name}】','{:url('Role/roleCompetence',['id'=>$vo.ag_id])}','550')" >
                                                    <i class="layui-icon">&#xe613;</i>权限
                                                </a>
                                            {/eq}
                                            {eq name="check.RoleroleEdit" value="1"}
                                                <a href="javascript:;" onclick="common.openWindow('编辑角色','{:url('Role/roleEdit',['id'=>$vo.ag_id])}','500','360')" >
                                                    <i class="layui-icon">&#xe642;</i>编辑
                                                </a>
                                            {/eq}
                                            {eq name="check.RoleroleDel" value="1"}
                                                <a onclick="dataDel(this,'{$vo.ag_id}')" href="javascript:;" >
                                                    <i class="layui-icon">&#xe640;</i>删除
                                                </a>
                                            {/eq}
                                        </div>
                                    </td>
                                </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
                <!--<div class="layui-card-body ">-->
                    <!--<div class="page">-->
                        <!--{//$info|raw}-->
                    <!--</div>-->
                <!--</div>-->
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*分类展开收起的分类的逻辑*/
    $(function() {
        common.tableVertical()
    });
    /*全选*/
    common.selectCheckbox('checkbox','id[]');
    /*删除*/
    function dataDel(obj,id){
        layer.confirm('确认要删除这条数据吗？',function(){
            var index = layer.load();
            //发异步删除数据
            $.ajax({
               type:"post",
               url:"{:url('Role/roleDel')}",
               data:{id:id},
               dataType:'json',
               success:function (data) {
                   if(data.status === 1){
                       $(obj).parents("tr").remove();
                       layer.msg(data.info, {icon: 6,time:1500});
                   }else{
                       layer.msg(data.info, {icon: 5,time:1500});
                   }
                   layer.close(index);

               },
               error:function (data) {
                   console.log(data);
                   layer.msg("不好意思，出现了一点问题", {icon: 5});
               }
            });
        });
    }
    /*批量删除*/
    function dataDelAll() {
        //获取checkbox值
        var ids = common.getCheckboxVal();
        if(ids.length < 1){
            layer.msg('请选择需要操作的数据！',{time:1500, icon:5});
            return false;
        }
        layer.confirm('确认要删除选中的数据吗？',function(){
            var index = layer.load();
            $.ajax({
                type: 'POST',
                url: "{:url('Role/roleDelAll')}",
                data: {ids:ids},
                dataType:'json',
                success:function(data){
                    if(data.status === 1){
                        layer.msg(data.info,{time:1500, icon:6},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.info,{time:1500, icon:5});
                    }
                    layer.close(index);
                },
                error:function(data){
                    console.log(data);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                    layer.close(index);
                }
            });

        });
    }
</script>
</html>